﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Ocmf.Forms;

namespace Ocmf.Types
{
    public class HouseLight : Action
    {
        private bool lightState;
        public bool LightState
        {
            get
            {
                return lightState;
            }
            set
            {
                lightState = value;
                Text = "House Light: " + (lightState ? "On" : "Off");
            }
        }
        
        public HouseLight()
        {
            Text = "House Light: " + (lightState ? "On" : "Off");
            ImageKey = SelectedImageKey = "houselight";
        }

        public override object Clone()
        {
            var clone = base.Clone() as HouseLight;
            clone.LightState = LightState;
            return clone;
        }

        public override System.Windows.Forms.Form Editor
        {
            get { return new EditHouseLightActionForm(this); }
        }

        public override XmlElement ToXml(XmlDocument xmlDocument)
        {
            //create trial xml element
            var houseLightElement = xmlDocument.CreateElement("HouseLight");
            //create, set and add attribute
            var lightStateAttribute = xmlDocument.CreateAttribute("LightState");
            lightStateAttribute.InnerText = LightState.ToString();
            houseLightElement.Attributes.Append(lightStateAttribute);
            //return element
            return houseLightElement;
        }

        public override void FromXml(XmlNode xmlElement)
        {
            LightState = bool.Parse(xmlElement.Attributes["LightState"].InnerText);
        }
    }
}
